package io.bdmc.modules.bss.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.bdmc.common.annotation.SysLogger;
import io.bdmc.common.utils.R;
import io.bdmc.common.validator.ValidatorUtils;
import io.bdmc.common.validator.group.UpdateGroup;
import io.bdmc.modules.bss.entity.SmkPush;
import io.bdmc.modules.bss.service.ISmkPushService;
import io.bdmc.modules.sys.controller.AbstractController;
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author HuangLu
 * @since 2019-01-24
 */
@RestController
@RequestMapping("/bss/push")
public class SmkPushController extends AbstractController{
    @Autowired
    private ISmkPushService _pushSvs;


	@RequestMapping("/info")
	//@RequiresPermissions("bss:push:info")
	public R info(){
        Wrapper<SmkPush> w = new QueryWrapper<SmkPush>().eq("user_id",getUserId());
        SmkPush p =_pushSvs.getOne(w);
		return R.ok().putData(p);
    }


    /**
	 * 新增或修改推送
	 */
	@SysLogger("新增或修改推送")
	@RequestMapping("/update")
	//@RequiresPermissions("bss:push:update")
	public R update(@RequestBody SmkPush push){
        ValidatorUtils.validateEntity(push, UpdateGroup.class);
        if(push.getPushId()!=null&&push.getPushId()>0){
            Boolean b = push.updateById();
            return R.trueOfFalse(b);
        }
        return R.error(-1,"推送参数错误");
    }

    
    /**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("bss:push:delete")
	public R delete(@RequestBody long pushId) {
		if(pushId>0)
		_pushSvs.removeById(pushId);
		return R.ok();
	}
}

